home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96b.txt / 000051_icon-group-sender _Wed Nov 6 17:29:28 1996.msg < prev    next >
Internet Message Format  |  1997-01-02  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 6 Nov 1996 16:41:39 MST
  2. To: icon-group@cs.arizona.edu
  3. Date: 6 Nov 1996 17:29:28 GMT
  4. From: stephen@lila.york.ac.uk (stephen parker)
  5. Message-Id: <55qhto$66r@netty.york.ac.uk>
  6. Organization: a loss for words
  7. Sender: icon-group-request@cs.arizona.edu
  8. Subject: sets and structures
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11. i'm reading ``An Overview of the Icon Programming Language; Version 8''
  12. (Griswold).  the section on sets says: ``insert(S, x) has no effect if x
  13. is already in S''.
  14.  
  15. this appears to work for atomic types eg,
  16.  
  17.     procedure    main()
  18.         local    l, s
  19.     
  20.         s := set()    
  21.         while(l := read()) do
  22.             insert(s, l)
  23.         every l := !s do
  24.             write(l)
  25.     end
  26.  
  27. however, if if i try to insert a structure then it never fails,
  28.  
  29.     record    rec(a,b)
  30.     
  31.     procedure    main()
  32.         local    l, s
  33.     
  34.         s := set()    
  35.         while(l := read()) do {
  36.             a := l[1]
  37.             b := l[2:0]
  38.             
  39.             insert(s, rec(a,b))
  40.         }
  41.         every l := !s do
  42.             write(l.a, " ", l.b)
  43.     end
  44.  
  45. results in output like:
  46.  
  47. ; structest
  48. foo
  49. bar
  50. bar
  51. spam
  52. 
  53. b ar
  54. s pam
  55. f oo
  56. b ar
  57.  
  58. as you would expect for a list rather than a set.  so, what's the answer
  59. if you want to form a set of non-atomic types?  do i have to do it by
  60. hand?
  61.  
  62. i suppose the answer is to buy the book -- i will when i have chance.
  63.  
  64. stephen
  65.